{extend name="index/iframe" /}

{block name="content"}
<div style="padding: 10px 0 0 0;">
    <table id="tableBox" lay-filter="tableBox" class="layui-table">
        <thead>
            <th>名称</th>
            <th>文件名</th>
            <th>操作</th>
        </thead>
        <tbody>
            {volist name="arr" id="vo"}
                <tr>
                    <td>{$vo.name}</td>
                    <td><a href="{:url('GameList/get1')}?app_id={$Think.get.app_id}&file_name={$vo.file_name}">{$vo.file_name}</a></td>
                    <td>
                        <a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-green" id="{$vo.id}">上传</a>
                        <a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-danger del" file_name="{$vo.file_name}">删除</a>
                    </td>
                </tr>
            {/volist}
        </tbody>
    </table>
</div>

{/block}

{block name="css"}
<style>

</style>
{/block}

{block name="js"}
<script>
    layui.use(['form', 'laydate', 'element', 'upload', 'table'], function(){
        var form = layui.form
            ,$ = layui.$
            ,layer = layui.layer
            ,upload = layui.upload;

        upload.render({
            elem: '#upload1' //绑定元素
            ,accept: 'file'
            ,url: '{:url("GameList/upload1")}?name=软著&app_id={$Think.get.app_id}' //上传接口
            ,done: function(json){
                if(json.code==0){
                    $('#upload1').parent().prev().html('<a href="'+'{:url("GameList/get1")}'+'?app_id={$Think.get.app_id}&file_name='+json.data+'">'+json.data+'</a>');
                    layer.msg(json.msg, {icon: 1, time:1000})
                }else{
                    layer.msg(json.msg, {icon: 0, time:1000})
                }
            }
        });

        upload.render({
            elem: '#upload2' //绑定元素
            ,accept: 'file'
            ,url: '{:url("GameList/upload1")}?name=授权书&app_id={$Think.get.app_id}' //上传接口
            ,done: function(json){
                if(json.code==0){
                    $('#upload2').parent().prev().html('<a href="'+'{:url("GameList/get1")}'+'?app_id={$Think.get.app_id}&file_name='+json.data+'">'+json.data+'</a>');
                    layer.msg(json.msg, {icon: 1, time:1000})
                }else{
                    layer.msg(json.msg, {icon: 0, time:1000})
                }
            }
        });

        upload.render({
            elem: '#upload3' //绑定元素
            ,accept: 'file'
            ,url: '{:url("GameList/upload1")}?name=版号&app_id={$Think.get.app_id}' //上传接口
            ,done: function(json){
                if(json.code==0){
                    $('#upload3').parent().prev().html('<a href="'+'{:url("GameList/get1")}'+'?app_id={$Think.get.app_id}&file_name='+json.data+'">'+json.data+'</a>');
                    layer.msg(json.msg, {icon: 1, time:1000})
                }else{
                    layer.msg(json.msg, {icon: 0, time:1000})
                }
            }
        });

        upload.render({
            elem: '#upload4' //绑定元素
            ,accept: 'file'
            ,url: '{:url("GameList/upload1")}?name=批复&app_id={$Think.get.app_id}' //上传接口
            ,done: function(json){
                if(json.code==0){
                    $('#upload4').parent().prev().html('<a href="'+'{:url("GameList/get1")}'+'?app_id={$Think.get.app_id}&file_name='+json.data+'">'+json.data+'</a>');
                    layer.msg(json.msg, {icon: 1, time:1000})
                }else{
                    layer.msg(json.msg, {icon: 0, time:1000})
                }
            }
        });

        $('body').on('click', '.del', function(){
            var file_name = $(this).parent().prev().find('a').html();
            var obj = $(this);
            layer.confirm('确定要删除吗？', {offset: '250px'}, function(index){
                var load = layer.load();
                $.post('{:url("GameList/del1")}',{app_id: {$Think.get.app_id}, file_name:file_name}, function(json){
                    layer.close(load);
                    if(json.code==0){
                        layer.msg(json.msg, {icon: 1, time:1000})
                        obj.parent().prev().html('');
                    }else{
                        layer.msg(json.msg, {icon: 0, time:1000});
                    }
                }, 'JSON').error(function(){
                    layer.close(load);
                    layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
                });
            });
        })
    });
</script>
{/block}